home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / graphicgems4.lha / GemsIV / vec_mat / ray / Primitive.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-06  |  952 b   |  38 lines

  1. #include "Primitive.h"
  2.  
  3. Primitive::~Primitive(){};
  4.  
  5. /************************************************************************
  6. *                                    *
  7. * This method receives as parameter a list of intersections and the    *
  8. * number of intersections in the list. It scans the list and returns    *
  9. * the closest positive intersection, or 0.0 if no such intersection    *
  10. * exists.                                *
  11. *                                    *
  12. ************************************************************************/
  13.  
  14. double Primitive::closest_intersection(double *x, int x_num)
  15. {
  16. int    i;
  17. double    x_min = (x_num) ? x[0] : 0.0;
  18.  
  19. for (i=1; i<x_num; i++)
  20.     if (x[i] < x_min)
  21.     x_min = x[i];
  22. return x_min;
  23. }
  24.  
  25. /************************************************************************
  26. *                                    *
  27. * Input from stream.                            *
  28. *                                    *
  29. ************************************************************************/
  30.  
  31. istream& operator >> (istream& s, Primitive& a)
  32. {
  33. s >> *((Object3D*) &a);
  34. s >> a.col;
  35. s >> a.ph;
  36. return s;
  37. }
  38.